home *** CD-ROM | disk | FTP | other *** search
- /* Copyright (c) Mar, 1986 UMMC. All rights reserved
-
- Filename: mxmul.c
-
- Abstract: determines which header files must be included with each clip demo module
-
- Environment: UM/CLIP
-
- Revision History:
- Rev # Date Auth Reason
- ----- --------- ---- ----------------------------------
- 0.0 12-mar-86 js original implementation
- 0.1 28-apr-86 js converted to double precision
- =========================================================================================
- NAME:
-
- mxmul - matrix multiplication
-
- SYNOPSIS:
-
- ERRCODE mxmul(mx1, r1, c1, mx2, r2, c2, mxout)
-
- DOUBLE *mx1; pointer to array containing input matrix 1
- INT r1; # of rows in input matrix 1
- INT c1; # of collumns in input matrix 1
- DOUBLE *mx2; pointer to array containing input matrix 2
- INT r2; # of rows in input matrix 2
- INT c2; # of collumns in input matrix 2
- DOUBLE *mxout; pointer to array for output matrix
-
- MODIFIED ARGUMENTS:
-
- none
-
- FUNCTION:
-
- This subroutine performs a standard matrix multiplication of mx1 and mx2 yielding the output
- matrix mxout. The formula for any given element of mxout, result(i,j) is given by:
-
- result(i,j) = mx1(i,1) x mx2(1,j) + mx1(i,2) x mx2(2,j) + ......
-
- PROGRAMMING NOTES:
-
- Since the arrays are passed as pointers, mxout must have enough space to store the entire
- result or memory will be inadvertently over-written. The output matrix will have the dimensions:
-
- rowsout = r1 colsout = c2
-
- EXAMPLES:
-
- =========================================================================*/
-
- #include "clipinclude.h"
-
- ERRCODE mxmul(mx1, r1, c1, mx2, r2, c2, mxout)
-
- DOUBLE *mx1; /* pointer to array containing input matrix 1 */
- INT r1; /* # of rows in input matrix 1 */
- INT c1; /* # of columns in input matrix 1 */
- DOUBLE *mx2; /* pointer to array containing input matrix 2 */
- INT r2; /* # of rows in input matrix 2 */
- INT c2; /* # of columns in input matrix 2 */
- DOUBLE *mxout; /* pointer to array for output matrix */
-
- {
-
- INT i; /* index for inner loop */
- INT rout, cout, index; /* indices into mxout */
- ERRCODE erret = OK; /* error code (init to OK) */
-
-
- if (c1 != r2) /* check for matrix size mis-match */
- erret = ERMXSZ;
- else {
- for (rout = 0; rout < r1; rout++) { /* for all output rows */
- for (cout = 0; cout < c2; cout++) { /* for all output collumns */
-
- index = (rout * c2) + cout;
- mxout[index] = 0;
-
- for (i = 0; i < c1; i++) /* loop through appropriate values... */
- mxout[index] += (mx1[(rout * c1) + i] * mx2[(i * c2) + cout]);
- }
- }
- }
-
- /* all done */
-
- return (erret);
-
- }